package com.netty.demo10;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by Lxk on 2020/1/31.
 */
public class NioTest3 {

    public static void main(String[] args) throws Exception {
        FileOutputStream fileOutputStream = new FileOutputStream("NioTest3.txt");
        FileChannel channel = fileOutputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(512);
        byte[] message = "hello world".getBytes();
        for(int i = 0;i < message.length; i++){
            buffer.put(message[i]);
        }
        buffer.flip();

        channel.write(buffer);
        fileOutputStream.close();
    }

}
